import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
import { inject } from 'inversify';
import { provide } from 'inversify-binding-decorators';
import UserController from '../controllers/user.controller';

@provide(UserRoutes)
export default class UserRoutes {
  constructor(@inject(UserController) private userController: UserController) {}

  async register(fastify: FastifyInstance) {
    fastify.post('/', async (request: FastifyRequest<{
      Body: { name: string; email: string }
    }>, reply: FastifyReply) => {
      await this.userController.createUser(request, reply);
    });

    fastify.get('/:id', async (request: FastifyRequest<{
      Params: { id: string }
    }>, reply: FastifyReply) => {
      await this.userController.getUser(request, reply);
    });

    fastify.get('/', async (request: FastifyRequest, reply: FastifyReply) => {
      await this.userController.getAllUsers(request, reply);
    });
  }
}